<?php 
//$start_date = $this->session->userdata('start_date');
//$reason = $this->session->userdata('reason');
//print_r($edit);
//echo $edit['start_date'];
?>

<span><?php if($this->session->flashdata('leave_message')) {
echo '<div id="alert" class="alert alert-success"> ';
echo '<button type="button" class="close" data-dismiss="alert">&times;</button>';
echo ''.$this->session->flashdata('leave_message').'';
echo'</div>';
}?></span>

<div class="row-fluid">
<div class="span9">
<h3 class="widget-name">Apply For Leave</h3>
<?php echo form_open('user/leave/apply_leave'); ?>

<table width="100%">
  <tr>
  	<td> <label class="radio"> <input type="radio" checked="" name="leave_type" onclick="$('.multiple_days').hide()" /> Single Day</label></td>
	<td colspan="3"><label class="radio"><input type="radio" name="leave_type" onclick="$('.multiple_days').show()"/> Multiple Day</label></td>
  </tr>
  <tr>
    <td><b>To :</b></td> 
    <td>
	<input type="text" name="start_date" class="datepicker"  value="<?= isset($edit['start_date']) ? $edit['start_date'] : set_value('start_date'); ?>"/>
	<span class="multiple_days" style="display:none;">
	<b>From : </b><input type="text" name="end_date" class="datepicker"  value="<?= isset($edit['end_date']) ? $edit['end_date'] : set_value('end_date'); ?>"/>	
	</span>
    <br />
    <?= form_error('start_date');?>
    </td>
    </tr>
  <tr>
    <td><b>Reason</b></td>
    <td><textarea class="span10" name="reason"><?= isset($edit['reason']) ? $edit['reason'] : set_value('reason'); ?></textarea>
      <br />
      <?= form_error('reason');?>
    </td>
     </tr> 
  <tr>
    <td>&nbsp;</td>
    <td>
    <input type="hidden" value="<?= isset($edit['id']) ? $edit['id'] : set_value('edit_id'); ?>" name="edit_id" /> 
    <input type="submit" class="btn btn-info btn-small" value="<?= isset($edit['id']) ? 'Update Leave' : 'Apply Leave' ?>" />
      <input type="reset" value="Reset Fields" class="btn btn-warning btn-small" />
    </td>
    </tr>
</table>
</form>
<hr />
<div>

</div>

<div>

<h4 class="text-info widget-name">Pending Leave Status <span class="pull-right"> <i class="icon-collapse collapse-widget" style="cursor:pointer"></i> </span></h4>
<table class="table table-condensed collapse-content">
<thead>
<tr>
<th>Reason</th>
<th>Applied On</th>
<th>Status</th>
<th width="5%">Action</th>
</tr>
</thead>
<?php 
foreach($leaves as $leave_stat)
{
?>
<tr>
<td><?= $leave_stat->reason;?></td>
<td><?php echo $leave_stat->applied_on;?></td>
<td> <span class="<?php if($leave_stat->status == 'verified'){echo 'text-success';}else{echo 'text-error';}?>"><?php echo $leave_stat->status;?></span> on <span class="muted"><?php echo $leave_stat->updated;?></span></td>
<td> 

<a href="javascript:void(0)" onclick="$('.details<?php echo $leave_stat->id; ?>').toggle(600);" > <i class="icon-plus-sign"></i></a>
<a href="<?php echo site_url('user/leave/delete/'.$leave_stat->id)?>"><i class="icon-trash"></i></a> </td>
</tr>
<?php 
$dates = $this->leave_model->get_leave_dates($leave_stat->id);
foreach($dates as $date){ ?>

<tr class="details<?php echo $leave_stat->id; ?> success" style="display:none;">	
	<!--<table class="table table-bordered">
	<tr>-->
	<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $date->date;?></td>	
	<td><?php echo $date->status;?></td>
	<td> <a href="<?php echo site_url('user/leave/delete_particular/'.$date->id);?>" onclick="return confirm('Do You Want to delete')" > <i class="icon-trash"></i> </a></td>
	<!--</tr>
	</table>-->
</tr>

<?php }}?>
</table>

<br />
<h4 class="widget-name orange">Verified/Rejected Leave Status <span class="pull-right"> <i class="icon-collapse collapse-widget" style="cursor:pointer"></i> </span></h4>
<table class="table table-condensed collapse-content">
<thead>
<tr>
<th>Reason</th>
<th>Applied On</th>
<th>Status</th>
<th width="5%">Action</th>
</tr>
</thead>
<?php 
foreach($leaves_verified as $leave_stat)
{
?>
<tr>
<td><?= $leave_stat->reason;?>
	<br>
	<b class="text-info">Remarks:</b> <?php if(!empty($leave_stat->remarks)){ echo ucfirst($leave_stat->remarks); }?>
</td>
<td><?php echo $leave_stat->applied_on;?></td>
<td> <span class="<?php if($leave_stat->status == 'verified'){echo 'text-success';}else{echo 'text-error';}?>"><?php echo $leave_stat->status;?></span> on <span class="muted"><?php echo $leave_stat->updated;?></span></td>
<td> 

<a href="javascript:void(0)" onclick="$('.details<?php echo $leave_stat->id; ?>').toggle(600);" > <i class="icon-plus-sign"></i></a>
<a href="<?php echo site_url('user/leave/delete/'.$leave_stat->id)?>"><i class="icon-trash"></i></a> </td>
</tr>
<?php 
$dates = $this->leave_model->get_leave_dates($leave_stat->id);
foreach($dates as $date){ ?>

<tr class="details<?php echo $leave_stat->id; ?> success" style="display:none;">	
	<!--<table class="table table-bordered">
	<tr>-->
	<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $date->date;?></td>	
	<td><?php echo $date->status;?></td>
	<td> <a href="<?php echo site_url('user/leave/delete_particular/'.$date->id);?>" onclick="return confirm('Do You Want to delete')" > <i class="icon-trash"></i> </a></td>
	<!--</tr>
	</table>-->
</tr>

<?php }}?>
</table>
<?php ?>
</div>

</div>
<div class="span3">
<h4 class="widget-name">Overall Leave Status</h4>
<p class="text-info " style="text-align: center"> You can take at a average of 1 leave per month</p>
<strong class="text-success">Total Leave allocated : <?php echo $total_leave_allocated;?></strong>
<br /><strong class="text-info">Total Leave Granted : <?= $leave_granted;?> </strong>

<hr style="margin:0;" />
<strong class="text-error">Total Leave Remaining : <?php echo $leave_remaning ;?></strong>
</div>
</div>


<script type="text/javascript">

$(".collapse-widget").live('click',function(){
	
	//$(this).next().toggle();
	// alert($(".collapse-widget").next().attr('class'));

	//$(".collapse-content").toggle();	
	/*if(showOrHide === true){
	$(".collapse-content").show();	
	}else if(showOrHide === false){
		  	$(".collapse-content").hide();
		  }*/
	/*if($(".collapse-content").hide()){
		$(this).attr('class','icon-collapse-top collapse-widget');
	}else {
		$(".collapse-content").show();
		$(this).attr('class','icon-collapse collapse-widget');
	}*/
	/*if($(this).attr('class','icon-collapse-top collapse-widget')){
		$(this).attr('class','icon-collapse collapse-widget');
	}*/
})

</script>